package com.atguigu.gmall.order.config;

import com.atguigu.gmall.rebbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class OrderCanelMqConfig {
    @Bean
    public Queue cancelOrderQueue(){
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }

    @Bean
    public Queue closePaymentQueue(){
        return QueueBuilder.durable(MqConst.QUEUE_PAYMENT_CLOSE).build();
    }

    @Bean
    public Exchange cancelOrderExchange(){
        Map map=new HashMap<>();
        map.put("x-delayed-type","direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false
                ,map);
    }

    @Bean
    public Binding cancelOrderBinding(){
        return BindingBuilder.bind(cancelOrderQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

    @Bean
    public Binding closePaymentBinding(){
        return BindingBuilder.bind(closePaymentQueue()).to(cancelOrderExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }
}
